package org.datedemo;

import java.util.Calendar;
import java.util.Locale;


//mysql
public class Calendar1 {
    public static void main(String[] args) {
        //TimeZone.setDefault(TimeZone.getTimeZone("PRC"));

        //设置时区
        //TimeZone.setDefault(TimeZone.getTimeZone("GMT+01:00"));

        //地区语言
        //Locale.setDefault(Locale.ENGLISH);

        var c = Calendar.getInstance();
        System.out.printf("%tF %<tT %<tA %<tp%n", c);
        //c.get();
        System.out.println(c.get(Calendar.YEAR));
        System.out.println(c.get(Calendar.MONTH) + 1);
        System.out.println(c.get(Calendar.DATE));

        System.out.println(c.get(Calendar.HOUR_OF_DAY));//时
        System.out.println(c.get(Calendar.MINUTE));//分
        System.out.println(c.get(Calendar.SECOND));//秒
        System.out.println(c.get(Calendar.MILLISECOND));//毫秒

        //毫秒数long
        System.out.println(c.getTime().getTime());
        System.out.println(c.getTimeInMillis());
        System.out.println(System.currentTimeMillis());

        //c.set(); 设置日期
        c.set(1988, Calendar.MAY, 3);
        c.set(Calendar.HOUR_OF_DAY, 5);
        System.out.printf("%tF %<tT %<tA %<tp%n", c);

        //System.currentTimeMillis();系统日期戳
        //c.getTimeInMillis(); 设置日期时间戳

        //Calendar.DAY_OF_WEEK 1-7 1星期日 2星期一 3星期二 - 7星期六


        //c.add();
        Calendar dd = Calendar.getInstance(Locale.US);
        Locale.setDefault(Locale.US);
        dd.add(Calendar.DATE, -1);
        for (int i = 0; i <= 10; i++) {
            dd.add(Calendar.DATE, 1);
            System.out.printf("%tF %<tT %<tA %<tp%n", dd);
        }

        Calendar c2 = Calendar.getInstance();
        //c2.add(Calendar.DAY_OF_MONTH, -7);
        //c2.add(Calendar.WEEK_OF_YEAR,-1);
        //System.out.printf("%tF %<tT %<tA %<tp%n", c2);
        System.out.printf("%tF %<tT %<tA %<tp%n", c2);
        c2.add(Calendar.MINUTE,30);
        System.out.printf("%tF %<tT %<tA %<tp%n", c2);

        //获取c2日历对象的一年的第几周 23
        //System.out.println(c2.get(Calendar.WEEK_OF_YEAR));

        System.out.println("----------------------------");
        Calendar c3 = Calendar.getInstance();
        //获取当前月第一天日期
        c3.set(Calendar.DATE,1);
        System.out.printf("%tF %<tT %<tA %<tp%n", c3);

        //当前日期
        c3 = Calendar.getInstance();
        System.out.printf("%tF %<tT %<tA %<tp%n", c3);

        //获取当前月最后一天日期
        c3.set(Calendar.MONTH, c3.get(Calendar.MONTH) + 1);
        c3.add(Calendar.DATE,-c3.get(Calendar.DATE));
        c3.set(Calendar.HOUR_OF_DAY,23);
        c3.set(Calendar.MINUTE,59);
        c3.set(Calendar.SECOND,59);
        c3.set(Calendar.MILLISECOND,999);
        System.out.printf("%tF %<tT %<tA %<tp%n", c3);

        //long t1 = c.getTime().getTime();
        //long t2 = System.currentTimeMillis();
        //long t3 = new Date().getTime();

        //Calendar - Date

        Calendar c5 = Calendar.getInstance();
        c5.set(2023,Calendar.OCTOBER,1);
        System.out.printf("%tF %<tT %<tA %<tp%n", c5);
        System.out.printf("%tA%n",c5);

    }
}
